<?php exit;
/*补充$thread[]数组:有可能前面已经提取出内容了,不必重复查询*/
if(empty($threadext_data))
{
    $threadext_data = db_find_one($theadext_table, array('tid' => $tid),array());
}
$reviseerr_delay=false;//是否还有没有处理的纠错或者修订
$reviseerr_delay_tip= '有修订或者纠错信息没有处理';
if(!empty($threadext_data)){
    foreach($threadext_data as $rsColName => &$rsColVal){
        if(!in_array($rsColName,array('tid'))){
        $thread[$rsColName] = $rsColVal;
        if ($rsColName == 'reviseerr' && !empty($rsColVal))
            $reviseerr_delay = true;
        }
    }
    if(isset($thread['keywords']) && !empty($thread['keywords']))	$header['keywords'] = $thread['keywords'];
    if(isset($thread['metadesc']) && !empty($thread['metadesc']))	$header['description'] = $thread['metadesc'];
}

if ($PostFlagEnabled) {
    $GLOBALS['CurrentPostFlags'] = null;
    $PostFlagsManageData = GetViewPostFlags($uid, 'manage');
    $PostFlagsMarkData = GetViewPostFlags($uid, 'mark');
    $firstpid = intval($thread['firstpid']);//主帖的id
    if($postlist == null) $postlist = array();
    $has_firstpid = isset($postlist[$firstpid]);
    if(!$has_firstpid) $postlist[$firstpid] = &$first;//主题也有标记:
    if (!empty($postlist)) {//对帖子的显示再处理:
        $pid_list = array_keys($postlist);
        $pid_list[] = $firstpid;//附加主帖的id
        $pid_ids = '(' . implode(',', $pid_list) . ')';
        $findpostflag_sql = 'SELECT * FROM `' . $db->tablepre . $PostFlagCfg['table'] . '` WHERE hide=0 AND pid IN ' . $pid_ids;
        $CurrentPostFlags = db_sql_find($findpostflag_sql, 'pid');//注:测试结果IN语句比OR快
        //$CurrentPostFlags = db_find($PostFlagCfg['table'], array('hide'=>0, 'pid' => array('='=>$pid_list)),array(),1,$pagesize,'pid');
        if (!empty($CurrentPostFlags)) {
            $_curGid = intval($gid);
			$sysColumns = array('id','pid', 'hide','fid','tid','isfirst');//系统字段
            $PostFlagNodesCfg = &$PostFlagCfg['Flags'];
            foreach ($CurrentPostFlags as $curPid => &$_PostFlagRow) {
                $post_AdditionClass = '';//追加的classname
                $other_post_AdditionStamp = array();//追加的icon
                foreach ($_PostFlagRow as $_fgFieldK => &$_fgFieldV) {
                    if (in_array($_fgFieldK,$sysColumns) || empty($_fgFieldV)) continue;
                    $_K_N = substr($_fgFieldK, 0, -2);
                    if (!isset($PostFlagNodesCfg[$_K_N]) || (isset($PostFlagNodesCfg[$_K_N]['enable']) && !boolval($PostFlagNodesCfg[$_K_N]['enable']))) continue;//不存在此标记名或者无效
                    $_K_t2 = substr($_fgFieldK, -2);
                    $F_denied = false;
                    if ('_g' == $_K_t2) {
                        $_PostFlagNodeDisplayGroup = $PostFlagNodesCfg[$_K_N]['DisplayGroup'];
                        $_PostFlagNodeAdditionClass = $PostFlagNodesCfg[$_K_N]['AdditionClass'];
                        if(!empty($PostFlagNodesCfg[$_K_N]['stamp']) || !isset($PostFlagNodesCfg[$_K_N]['stamp'])) {
                            if(isset($PostFlagNodesCfg[$_K_N]['stamp']) && is_string($PostFlagNodesCfg[$_K_N]['stamp']) && !in_array(strtolower($PostFlagNodesCfg[$_K_N]['stamp']),array('false','no','off','close','nothing','hide')))
                                $other_post_AdditionStamp[$_K_N] = $PostFlagNodesCfg[$_K_N]['stamp'];
                            else
                                $other_post_AdditionStamp[$_K_N] = $_K_N;
                        }
                        if (!empty($_PostFlagNodeAdditionClass))  $post_AdditionClass .= ' ' . $_PostFlagNodeAdditionClass;
                        if (!empty($_PostFlagNodeDisplayGroup) && $_curGid != 1 && $_curGid != 2) {//管理员与超级版主都会显示
                            if (!in_array($_curGid, $_PostFlagNodeDisplayGroup, true)) {
                                if (in_array(USERSELF, $_PostFlagNodeDisplayGroup, true)) {
                                    if ($_PostFlagRow[$_K_N . '_u'] != $postlist[$curPid]['user']['uid']) {//帖子作者本人可见
                                        $F_denied = true;
                                    }
                                } else
                                    $F_denied = true;
                            }
                        }
                    }
                    if ($F_denied) {
                        $postlist[$curPid]['message_fmt'] = '禁止查看。(Forbidden to view!)<br/><span class="forbiddeninfo">['.$PostFlagNodesCfg[$_K_N]['title'].']:'.$_PostFlagRow[$_K_N].'</span>';
                        unset($postlist[$curPid]);
                        break;
                    }
                }
                if (!$F_denied){
                    $opt_post_hander = null;
                    if($firstpid == $curPid) $opt_post_hander = &$first;//主帖,$first['message_fmt']
                    elseif(isset($postlist[$curPid])) $opt_post_hander = &$postlist[$curPid];
                    if($opt_post_hander !== null) {
                        if (!empty($post_AdditionClass)) {
                            $opt_post_hander['classname'] .= $post_AdditionClass;
                        }
                        if (!empty($other_post_AdditionStamp)) {
                            $other_post_AdditionStamp_html = '<ul class="post_icons ghx_stamp">';
                            foreach ($other_post_AdditionStamp as $pai => &$_paiStamp) {
                                $pai_title = $PostFlagNodesCfg[$pai]['title'];
                                $other_post_AdditionStamp_html .= "<li class=\"ghx_stamp_{$_paiStamp}\" title=\"{$pai_title}\" data-flag=\"{$pai}\">&nbsp;&nbsp;</li>";
                            }
                            $other_post_AdditionStamp_html .= '</ul>';
                            $opt_post_hander['message_fmt'] = $other_post_AdditionStamp_html . $opt_post_hander['message_fmt'];
                            unset($pai_title, $other_post_AdditionStamp_html);
                        }
                        unset($opt_post_hander);
                    }
                }
            }
            unset($F_denied, $_curGid, $curPid, $_fgFieldK, $_K_N, $_K_t2, $post_AdditionClass);
        }
        unset($pid_list, $pid_ids, $findpostflag_sql);
    }
    if(!$has_firstpid) unset($postlist[$firstpid]);//恢复
}
if(!isset($FrontRelatedLinkShow))
    $FrontRelatedLinkShow = &GetPluginCfgNode('ArticleKeyWord/FrontRelatedLinkShow');
$RelatedLinkData = null;
if($FrontRelatedLinkShow > 0 && isset($threadext_data['relatedlinks']) && !empty($threadext_data['relatedlinks'])){
    $RelatedLinkData = RelatedlinksToViewArray($threadext_data['relatedlinks'],array('id','title','url','mark'));
}
//获取对应的模板文件(可能动态生成,暂时不判断是否存在):
if(!empty($threadext_data['viwetemplate'])){
    $view_template_paths = $threadext_data['viwetemplate'];
}
else{
    $tmp_vtp = &GetForumDefaultTemplate($fid);
    if(!empty($tmp_vtp)) $view_template_paths = &$tmp_vtp;
    unset($tmp_vtp);
}


